﻿#pragma execution_character_set("utf-8")
#include "DefectMapSetting.h"

DefectMapSettingDlg::DefectMapSettingDlg(QDialog* parent)
	: QDialog(parent)
{
	ui.setupUi(this);
	connect(ui.btnColor1, &QtColorButton::colorChanged, this, &DefectMapSettingDlg::slot_btnColor);
	connect(ui.btnColor2, &QtColorButton::colorChanged, this, &DefectMapSettingDlg::slot_btnColor);
	connect(ui.btnColor3, &QtColorButton::colorChanged, this, &DefectMapSettingDlg::slot_btnColor);
	connect(ui.btnColor4,&QtColorButton::colorChanged,this, &DefectMapSettingDlg::slot_btnColor);
}

DefectMapSettingDlg::~DefectMapSettingDlg()
{

}

void DefectMapSettingDlg::initBlemishInfo(void* pdata)
{
	p_data = pdata;
	QVector<DefectMapInfo>* p_blemishMap = (QVector<DefectMapInfo>*)p_data;

	ui.lineEdit_Type_1->setText((*p_blemishMap)[0].symbolName);
	ui.lineEdit_Type_2->setText((*p_blemishMap)[1].symbolName);
	ui.lineEdit_Type_3->setText((*p_blemishMap)[2].symbolName);
	ui.lineEdit_Type_4->setText((*p_blemishMap)[3].symbolName);

	addComboxItem(ui.comboBox_Type_11);
	addComboxItem(ui.comboBox_Type_12);
	addComboxItem(ui.comboBox_Type_13);
	addComboxItem(ui.comboBox_Type_14);

	ui.comboBox_Type_11->setCurrentIndex((*p_blemishMap)[0].symbolType);
	ui.comboBox_Type_12->setCurrentIndex((*p_blemishMap)[1].symbolType);
	ui.comboBox_Type_13->setCurrentIndex((*p_blemishMap)[2].symbolType);
	ui.comboBox_Type_14->setCurrentIndex((*p_blemishMap)[3].symbolType);

	
	ui.btnColor1->setColor((*p_blemishMap)[0].color);
	ui.btnColor2->setColor((*p_blemishMap)[1].color);
	ui.btnColor3->setColor((*p_blemishMap)[2].color);
	ui.btnColor4->setColor((*p_blemishMap)[3].color);



}

void DefectMapSettingDlg::addComboxItem(QComboBox* box)
{
	box->addItem("无显示");
	box->addItem(".");
	box->addItem("×");
	box->addItem("＋");
	box->addItem("○");
	box->addItem("●");
	box->addItem("□");
	box->addItem("◇");
	box->addItem("*");
	box->addItem("△");
	box->addItem("其他1");
	box->addItem("其他2");
	box->addItem("其他3");
	box->addItem("其他4");
	box->addItem("CrossCircle");
	box->addItem("PlusCircle");
}

void DefectMapSettingDlg::on_pushButton_Save_clicked()
{
	QVector<DefectMapInfo>* p_blemishMap = (QVector<DefectMapInfo>*)p_data;

	(*p_blemishMap)[0].symbolName = ui.lineEdit_Type_1->text();
	(*p_blemishMap)[1].symbolName = ui.lineEdit_Type_2->text();
	(*p_blemishMap)[2].symbolName = ui.lineEdit_Type_3->text();
	(*p_blemishMap)[3].symbolName = ui.lineEdit_Type_4->text();

	(*p_blemishMap)[0].symbolType = ui.comboBox_Type_11->currentIndex();
	(*p_blemishMap)[1].symbolType = ui.comboBox_Type_12->currentIndex();
	(*p_blemishMap)[2].symbolType = ui.comboBox_Type_13->currentIndex();
	(*p_blemishMap)[3].symbolType = ui.comboBox_Type_14->currentIndex();



	this->close();
}

void DefectMapSettingDlg::on_pushButton_Cannel_clicked()
{
	this->close();
}

void DefectMapSettingDlg::slot_btnColor(const QColor& color)
{
	auto objName = sender()->objectName();
	QVector<DefectMapInfo>* p_blemishMap = (QVector<DefectMapInfo>*)p_data;
	if (objName == "btnColor1")
	{
		(*p_blemishMap)[0].color = color;
	}
	if (objName == "btnColor2")
	{
		(*p_blemishMap)[1].color = color;
	}
	if (objName == "btnColor3")
	{
		(*p_blemishMap)[2].color = color;
	}
	if (objName == "btnColor4")
	{
		(*p_blemishMap)[3].color = color;
	}
}
